package com.shkco.system.controller;

import com.shkco.basic.util.PageList;
import com.shkco.basic.util.AjaxResult;
import com.shkco.system.domain.Systemdictionarydetail;
import com.shkco.system.query.SystemdictionarydetailQuery;
import com.shkco.system.service.ISystemdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarydetail")
public class SystemdictionarydetailController {

    @Autowired
    private ISystemdictionarydetailService systemdictionarydetailService;


    @GetMapping("/{id}")
    public Systemdictionarydetail findById(@PathVariable("id")Long id){
        return systemdictionarydetailService.findById(id);
    }

    @GetMapping
    public List<Systemdictionarydetail> findAll(){
        return systemdictionarydetailService.findAll();
    }

    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable("id")Long id){
        try {
            systemdictionarydetailService.del(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    @PutMapping
    public AjaxResult addOrUpt(@RequestBody Systemdictionarydetail systemdictionarydetail){
        try {
            if (systemdictionarydetail.getId() == null){
                systemdictionarydetailService.add(systemdictionarydetail);
            } else {
                systemdictionarydetailService.update(systemdictionarydetail);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    @PostMapping
    public PageList<Systemdictionarydetail> pageQuery(@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery){
        return systemdictionarydetailService.queryPage(systemdictionarydetailQuery);
    }

    @PatchMapping
    public AjaxResult patchDel(@RequestBody List<Long> ids){
        try {
            systemdictionarydetailService.patchDel(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    @GetMapping("/detail")
    public List<Systemdictionarydetail> findDetail(@RequestBody Long id){
        return systemdictionarydetailService.findDetail(id);
    }

}
